
package com.dps.omc.action;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dps.omc.service.IJobLogService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dps.common.domain.view.BizData4Page;
import com.dps.omc.model.JobLog;
import com.dps.common.utils.IdGenerator;
import com.dps.common.utils.JsonResult;
import com.dps.common.utils.PageParam;
import com.dps.common.utils.Constants;

@Controller
public class JobLogAction extends AbstractAdminController<IJobLogService>{

    @Autowired
    private IJobLogService jobLogService;
    
    @RequestMapping(value="/joblog/list")
    public String list(Date createDateStart, Date createDateEnd,JobLog jobLog, ModelMap model, PageParam pageParam, HttpServletRequest request, HttpServletResponse response){

        //获取参数
    	Map<String, Object> conditions = getQueryMap(jobLog);
		conditions.put("createDateStart",createDateStart);
		conditions.put("createDateEnd",createDateEnd);
    	BizData4Page<JobLog> pageCtx = doPage(model, conditions, pageParam);
    	model.addAttribute("jobLog", jobLog);
		model.addAttribute("createDateStart",createDateStart);
		model.addAttribute("createDateEnd",createDateEnd);
    	return "/module/joblog/list";
    }    
    
    @RequestMapping(value="/joblog/add")
    public String add(ModelMap model,HttpServletRequest request,HttpServletResponse response){

    	model.addAttribute("jobLog", new JobLog());
        return "module/joblog/edit";
    }    
    
    @RequestMapping(value="/joblog/edit")
    public String edit(String id,ModelMap model,HttpServletRequest request,HttpServletResponse response){
    	
    	JobLog jobLog = jobLogService.fetch(id);
    	model.addAttribute("jobLog", jobLog);
        return "module/joblog/edit";
    }    
    
    @RequestMapping(value="/joblog/save")
    @ResponseBody
    public String save(HttpServletRequest request,JobLog jobLog){
		boolean isAddNew = StringUtils.isBlank(jobLog.getId())?true:false;
		if(isAddNew)
		{
			jobLog.setId(IdGenerator.createNewId());
			jobLogService.add(jobLog);
		}
		else
		{
			jobLogService.update(jobLog);
		}
        return JsonResult.saveSuccessClose(Constants.MAIN_TAB).toString();
    }    
    
    @RequestMapping(value="/joblog/delete")
    @ResponseBody
    public String delete(String ids,HttpServletRequest request){
    	
    	jobLogService.deleteByIds(ids);
    	return JsonResult.DELETE_SUCCESS.toString();
    }       
	
    protected Map getQueryMap(JobLog jobLog)
    {
    	Map<String, Object> conditions = new HashMap();
    	
		conditions.put("name", jobLog.getName());		
		conditions.put("groupType", jobLog.getGroupType());		
		conditions.put("subjectId", jobLog.getSubjectId());		
		conditions.put("artifactId", jobLog.getArtifactId());		
		conditions.put("artifactPath", jobLog.getArtifactPath());		
		conditions.put("templateId", jobLog.getTemplateId());		
		conditions.put("note", jobLog.getNote());		
		conditions.put("isuploadfile", jobLog.getIsuploadfile());		
		conditions.put("iscron", jobLog.getIscron());		
		conditions.put("cronexpr", jobLog.getCronexpr());		
		conditions.put("createrId", jobLog.getCreaterId());		
		conditions.put("createrName", jobLog.getCreaterName());		
		conditions.put("createDate", jobLog.getCreateDate());		
		conditions.put("status", jobLog.getStatus());		
		conditions.put("auditState", jobLog.getAuditState());		
		conditions.put("jobId", jobLog.getJobId());		
		conditions.put("lastModifiedTime", jobLog.getLastModifiedTime());		
		conditions.put("lastModifiedId", jobLog.getLastModifiedId());		
		conditions.put("lastModifiedName", jobLog.getLastModifiedName());		
    	return conditions;
    }

    @Override
    protected IJobLogService getMainService() {
        return jobLogService;
    }

    @Override
    protected String getMainObjName() {
        return "joblog";
    }

    @Override
    protected String getViewTitle() {
        return "joblog";
    }
}
